#!/usr/bin/env node

const mysql = require('mysql2/promise');

let con;

(async ()=>{
  con = await mysql.createConnection({
    host:'localhost',
    user:'root',
    password:'ddd',
    database:'todo'
  })
})();

async function insert(item){
  const sql = `insert into tasks(task) values("${item}")`;
  await con.query(sql);
}
async function getItems(){
  const sql = 'select * from tasks;';
  const [rows] = await con.query(sql);
  return JSON.stringify(rows)
}

module.exports = { getItems,insert };


